package com.xy.work.template.common.exception;
import com.xy.work.template.common.interfaces.BaseCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * 顶级自定义异常
 * @author niuniu
 */
@EqualsAndHashCode(callSuper=false)
@Data
public class BaseCustomException extends RuntimeException {

    private int code;
    private String msg;

    /**
     * 根据code码和异常消息内容定义初始化异常信息
     * @param code
     * @param msg
     */
    public BaseCustomException(int code, String msg){
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    /**
     * 根据枚举初始化异常信息
     * @param baseCodeEnum
     */
    public BaseCustomException(BaseCodeEnum baseCodeEnum){
        super(baseCodeEnum.getMessage());
        this.code = baseCodeEnum.getCode();
        this.msg = baseCodeEnum.getMessage();
    }


}
